using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;

namespace EssentialWCF
{
    [DataContract]
    public class Container
    {
        [DataMember]
        public double currencyA;

        [DataMember]
        public double currencyB;
    
    }

    [ServiceContract]
    public interface IStockService
    {
        [OperationContract]
        Container GetPrice(string ticker);

        [WebGet(ResponseFormat=WebMessageFormat.Json, UriTemplate="/ServiceTime")]
        [OperationContract]
        DateTime GetServiceTime();
    }

    public class StockService : IStockService
    {


        public Container GetPrice(string ticker)
        {
            var container = new Container();
            container.currencyA = 199;
            container.currencyB = 200;
            return container;
        }


        public DateTime GetServiceTime()
        {
            return DateTime.Now;
        }
    }

    public class service
    {
        public static void Main()
        {
           

            ServiceHost serviceHost = new ServiceHost(typeof(StockService), 
                                          new Uri("http://localhost:8000/EssentialWCF"));

            serviceHost.AddServiceEndpoint(
                    typeof(IStockService),
                    new WebHttpBinding(),
                    "");
            var webbehavior = new WebHttpBehavior();
            
            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            behavior.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(behavior);

            serviceHost.AddServiceEndpoint(
                    typeof(IMetadataExchange),
                    MetadataExchangeBindings.CreateMexHttpBinding(),
                    "mex");

            serviceHost.Open();

            // The service can now be accessed.
            Console.WriteLine("The services is ready. Press <ENTER> to terminate.\n\n");
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            serviceHost.Close();
            }
        }
    }

